<?php
include "otamu_config.php";

define("_VIEWPATH_","views/guru/");
$layout = "layout";

$OBJECT = 'master_staff';
$OBJECT_TABLE = $OBJECT;

if (!isset($_GET['act'])) $_GET['act'] = '';

class Institusi extends ADOdb_Active_Record
{
	var $_table = "master_institusi";
}

class Student extends ADOdb_Active_Record
{
	var $_table = "master_murid";
}

class Staff extends ADOdb_Active_Record
{
	var $_table = "master_staff";
}

class Gelaran extends ADOdb_Active_Record
{
	var $_table = "ref_gelaran";
}


switch ($_GET['act']) {
	case "search_guru" :
		
	break;

	case "new_guru_step1" :
		$guru = new Staff();
		if(isset($_REQUEST['nokp'])){
			if($guru->Load("nokp = '".$_REQUEST['nokp'] . "'")) {
				//echo $guru->nama;
				$str = "<script>alert('Guru sudah wujud di pangkalan data SPK')</script>";
				echo $str;
			}
			else 
				{ header("location: guru.jsp?act=new_staff&nokp=".$_REQUEST['nokp']);exit;}
				//echo "xde lagi pegi isi form";
			
		}
	break;
	
	case "new_staff" :
		$institusi = new Institusi();
		$institusi->Load("kod='".$_SESSION['ID_my_site']."'");
		
		$staff = new Staff();
		$staff->nokp = $_REQUEST['nokp'];
		//print_r($_REQUEST);
		// if submitted
		if($_REQUEST['save']):
			foreach ($_REQUEST[$OBJECT] as $k=>$v) {
				//print "$k -> $v <br/>";
				$staff->$k = $v;
			}
		
		
			// check if ici already exist ...
			if(!$staff->Load("nokp='$staff->nokp'")):
				if (!$staff->save()) {
					echo $staff->ErrorMsg();exit;
					$_SESSION['flash'] = $staff->ErrorMsg();
				}else {
					$_SESSION['flash'] = 'Staff berjaya diwujudkan.';
				}
			endif;
		endif;	
		
	break;
	
	default:
		$act = 'new_guru_step1';
}
include _VIEWPATH_."$layout.php";
$_SESSION['flash'] = '';
?>